package com.gla.Controller;

import com.gla.domain.*;
import com.gla.result.Result;
import com.gla.service.FYH_ShopService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/shop")
public class FYH_ShopController {
    @Resource
    FYH_ShopService fyh_shopService;

    @GetMapping("/getAllShop")
    public Result getAllShop(){
        List<Shop> allshop = fyh_shopService.selectAllShop();
        return Result.succeed(allshop);
    }

    @GetMapping("/getOneShop")
    public Result getOneShop(@RequestParam int shopid){
        Shop shop = fyh_shopService.selectOneShop(shopid);
        return Result.succeed(shop);
    }

    @GetMapping("/getCommodityByShopIdAndPOU")
    public Result getCommodityByShopId(@RequestParam int shopid, @RequestParam int pou){
        List<Commodity> list = fyh_shopService.selectCommodityByShopid(shopid, pou);
        return Result.succeed(list);
    }

    @GetMapping("/getCommodityById")
    public Result getCommodityById(@RequestParam int cmid){
        Commodity cm = fyh_shopService.selectCommodityById(cmid);
        return Result.succeed(cm);
    }

    @GetMapping("/getAllCommodityByPOU")
    public Result getAllCommodityByPOU(@RequestParam int pou){
        List<Commodity> lcm = fyh_shopService.selectAllCommodityByPOU(pou);
        return Result.succeed(lcm);
    }

    @GetMapping("/getAllEvaluationByCMId")
    public Result getAllEvaluationByCMId(@RequestParam int cmid){
        List<FYH_Evaluation> lfe = fyh_shopService.selectEvaluationByCMId(cmid);
        return Result.succeed(lfe);
    }

    @GetMapping("/getVedioByCMId")
    public Result getVedioByCMId(@RequestParam int cmid){
        List<FYH_Vedio> lfv = fyh_shopService.selectVedioByCMId(cmid);
        return Result.succeed(lfv);
    }

    @GetMapping("/getOneCarByCMIdAndUId")
    public Result getOneCarByCMIdAndUId(@RequestParam int cmid, @RequestParam int uid){
        FYH_ShopCar fs = fyh_shopService.selectOneCarByCMIdAndUId(cmid, uid);
        if(fs == null) return Result.succeed(new FYH_ShopCar());
        return Result.succeed(fs);
    }

    @GetMapping("/setOneCar")
    public Result setOneCar(@RequestParam int cmid, @RequestParam int uid){
        FYH_ShopCar fs = fyh_shopService.insertOneCar(cmid, uid);
        return Result.succeed(fs);
    }

    @GetMapping("/upOneCar")
    public Result upOneCar(@RequestParam int cid, @RequestParam int num){
        FYH_ShopCar fs = fyh_shopService.updateOneCar(cid, num);
        return Result.succeed(fs);
    }

    @GetMapping("/delOneCar")
    public Result delOneCar(@RequestParam int cid){
        FYH_ShopCar fs = fyh_shopService.deleteOneCar(cid);
        if(fs == null) return Result.succeed(new FYH_ShopCar());
        return Result.succeed(fs);
    }

    @GetMapping("/getOneVedio")
    public Result getOneVedio(@RequestParam int vid){
        FYH_Vedio fv = fyh_shopService.selectVedioById(vid);
        return Result.succeed(fv);
    }

    @GetMapping("/getVedioByType")
    public Result getVedioByType(@RequestParam int type, @RequestParam int id){
        List<FYH_Vedio> lfv = fyh_shopService.selectVedioByType(type, id);
        return Result.succeed(lfv);
    }

    @GetMapping("/getEvaBySPId")
    public Result getEvaBySPId(@RequestParam int spid){
        List<FYH_Evaluation> lfe = fyh_shopService.selectEvaluationBySPId(spid);
        return Result.succeed(lfe);
    }

    @GetMapping("/getShopNear")
    public Result getShopNear(@RequestParam String ula, @RequestParam String ulo){
        List<Shop> ls = fyh_shopService.selectShopNear(new Double(ula), new Double(ulo));
        return Result.succeed(ls);
    }
}
